<?php
require_once APP_PATH.'/sms/configs/sms_config.php';
class sms_model_announcement extends Model {
	public function __construct(){
		parent::__construct();
		$this->table = 'app_sms_announcement';
	}
	
	public function add($arguments){
		$arguments = filter_params($arguments, 'title', 'content');
		trim_params($arguments);
		$arguments['create_time'] = time();
		if($this->db->insert($this->table, $arguments)){
			MemRow::setCache(CACHE_KEY_SYS_ANNO, array('new_anno'=>1,'time'=>time()), 0);
			return true;
		}
		return false;
	}
	
	public function update($arguments){
		$arguments = filter_params($arguments, 'id', 'title', 'content');
		trim_params($arguments);
		return $this->db->update($this->table, $arguments);
	}
	
	public function delete($id){
		return $this->db->update($this->table, array('is_deleted'=>1), array('id'=>$id));
	}
	
	public function selectPage($page, $pageSize){
		$sql = "select * from ".$this->table." where is_deleted=0 order by id desc";
		return $this->db->selectPage($sql, array(), $page, $pageSize);
	}
	
	public function select($id){
		return $this->db->fetchRow('select * from '.$this->table.' where id=&id', array('id'=>$id));
	}
}